/*
 * Copyright (c) 2007-2008, Thomas Krause (tho.krause@gmail.com)
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * 
 *     * Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright notice,
 *       this list of conditions and the following disclaimer in the documentation
 *       and/or other materials provided with the distribution.
 *     * Neither the name of gidoo nor the names of its contributors may be used to
 *       endorse or promote products derived from this software without specific
 *       prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.gidoo.cms.data;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

/**
 * Represents a single page containing a "snapshot" of the content of a folder.
 * 
 * @see Folder
 * @author <a href="mailto:tho.krause@gmail.com">Thomas Krause</a>
 */
@Entity
public class Page implements Serializable
{
  
  private long id;
  
  private String title;
  
  private String contentAsXML;
  
  private RegisteredUser createdBy;
  
  private Date createdTime;
  
  private RegisteredUser publishedBy;
  
  private Date publishedTime;
  
  public Page()
  {
  }
  
  @Id
  @GeneratedValue
  public long getId()
  {
    return id;
  }

  public void setId(long id)
  {
    this.id = id;
  }

  /** 
   * Get the author which has created this page. Since pages are created once and
   * and the content is usally not changed but the page of a folder is exchanged
   * this is equivalent to a "last changed by". 
   */
  @ManyToOne
  @JoinColumn(nullable=false)
  public RegisteredUser getCreatedBy()
  {
    return createdBy;
  }

  /** 
   * Set the author which has created this page. Since pages are created once and
   * and the content is usally not changed but the page of a folder is exchanged
   * this is equivalent to a "last changed by". 
   */
  public void setCreatedBy(RegisteredUser createdBy)
  {
    this.createdBy = createdBy;
  }

  /**
   * Get the creation time (which is equivalent to the "last changed" time).
   */
  @Temporal(TemporalType.DATE)
  @Column(nullable=false)
  public Date getCreatedTime()
  {
    return createdTime;
  }

  /** Set the creation time (which is equivalent to the "last changed" time). */
  public void setCreatedTime(Date createdTime)
  {
    this.createdTime = createdTime;
  }

  /**
   * Get the publisher who is responsible for publishing the content of this page.
   */
  @ManyToOne
  public RegisteredUser getPublishedBy()
  {
    return publishedBy;
  }
  /**
   * Set the publisher who is responsible for publishing the content of this page.
   */
  public void setPublishedBy(RegisteredUser publishedBy)
  {
    this.publishedBy = publishedBy;
  }

  /**
   * Get the time when the publisher accepted the content of this page.
   */
  @Temporal(TemporalType.DATE)
  public Date getPublishedTime()
  {
    return publishedTime;
  }
  /**
   * Set the time when the publisher accepted the content of this page.
   */
  public void setPublishedTime(Date publishedTime)
  {
    this.publishedTime = publishedTime;
  }
  
  /**
   * Get the title of the page. Each page has a title which can be used for e.g.
   * creating menus.
   */
  @Column(nullable=false)
  public String getTitle()
  {
    return title;
  }

  /**
   * Set the title of the page. Each page has a title which can be used for e.g.
   * creating menus.
   */
  public void setTitle(String title)
  {
    this.title = title;
  }

  /**
   * Get the content of the page. The content is stored as XML that can be 
   * converting using the XSLT scripts of the CMS.
   */
  @Column(nullable=false)
  public String getContentAsXML()
  {
    return contentAsXML;
  }
  /**
   * Set the content of the page. The content is stored as XML that can be 
   * converting using the XSLT scripts of the CMS.
   */
  public void setContentAsXML(String xml)
  {
    this.contentAsXML = xml;
  }  
  
}
